<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>


<script type="text/javascript" src="${ctx}/js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="${ctx}/css/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="${ctx}/lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="${ctx}/lib/datatables/js/jquery.dataTables.js"></script>
<script type="text/javascript">
    /*$(document).ready(function() {
        $('#example').dataTable({
            "sPaginationType": "full_numbers"
        });
    });*/
</script>
<!-- DATATABLES CSS END -->

<h1 class="page-title">职等设置</h1>

<div class="container_12 clearfix leading">

    <div class="tabs side grid_8 leading">
        <p> 职务名称：
            <select id="duty_sel" onchange="onDutyChange(this)">
                <s:if test="#request.duties == null or #request.duties.size == 0">
                    <option value="0">请选择</option>
                </s:if>
                <s:iterator value="#request.duties" var="d" status="sta">
                    <option value="${d.id}">${d.dutyName}</option>
                </s:iterator>    
            </select>
        </p>
        <div class="clear"></div>
        <div class="grid_12">
            <div id="demo" class="clearfix">
                <table class="display" id="example">
                    <thead>
                    <tr>
                        <th>选择</th>
                        <th>职等名称</th>
                        <th>职级</th>
                        <th>职等职级工资</th>
                        <th>职等描述</th>
                        <th>福利方案</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <s:iterator value="#request.grades" var="g" status="sta">
                    <s:if test="#sta.even"> <tr class="gradeA"> </s:if><s:else><tr class="gradeC"></s:else>
                        <td><input type="checkbox" name="checkbox_grade" value="${g.id}"/></td>
                        <td>${g.gradeName}</td>
                        <td>${g.gradeSort}</td>
                        <td>${g.gradePay}</td>
                        <td>${g.gradeContent}</td>
                        <td>${g.salaryStructure.projectTitle}</td>
                        <td>
                            <span onclick="deleteGrade('${g.id}')" class="fy">删除</span>
                            <a href="#rank/grade_add.xhtml?grade.id=${g.id}&t=<%=new java.util.Date().getTime()%>"> <span class="fy">编辑</span> </a>
                        </td>
                    </tr>
                    </s:iterator>
                    </tbody>
                </table>
            </div>
            <div class="form-action clearfix">
                <p><%@ include file="/WEB-INF/pages/common/main_pager.jsp"%></p>
                <p>
                    <input type="checkbox" id="form-all" value="1" onchange="checkAll(this)"/><label for="form-all">全选</label>
                    <button class="button" type="button" onclick="deleteGrades()">批量删除</button>
                    <a class="button" href="#rank/grade_add.xhtml?t=<%=new java.util.Date().getTime()%>"><span style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>添加</a>
                </p>
            </div>
        </div>
    </div>
</div>

<form id="edit_form" name="edit_form" method="post"/>

<div class="clear"></div>


<script type="text/javascript" src="${ctx}/js/Tree.js"></script>
<script type="text/javascript">
    $(function(){
        $("#duty_sel").val("${currentDutyId}");
    });

    function onDutyChange(obj){
        var dutyId = $(obj).val();
        var url = "${ctx}/rank/grade_list.xhtml";
        refreshListContent(url, {"organizationId":"${organizationId}", "currentDutyId":dutyId});
    }
    
    function deleteGrade(gradeId) {
        if (confirm("确定要删除本条数据吗？")) {
            doDeleteGrades(gradeId);
        }
    }
    function deleteGrades() {
        var checkIds = new Array();
        $("input[type='checkbox'][name='checkbox_grade']").each(function() {
            if (this.checked) {
                checkIds.push(this.value);
            }
        });
        if (checkIds.length == 0) {
            return;
        }
        if (confirm("确定要删除选中的数据吗？")) {
            doDeleteGrades(checkIds.join(","))
        }
    }
    function doDeleteGrades(ids) {
        var url = "${ctx}/rank/grade_delete.xhtml";
        refreshListContent(url, {"organizationId":"${organizationId}", "gradeIds":ids});
    }

    function checkAll(o) {
        if (o.checked) {
            $("input[type='checkbox'][name='checkbox_grade']").attr("checked", true);
        } else {
            $("input[type='checkbox'][name='checkbox_grade']").attr("checked", false);
        }
    }
</script>

    